#include<bits/stdc++.h>
#define all(a) a.begin(), a.end()
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using pii = std::pair<int, int>;
using vii = std::vector<pii>;
using vi = std::vector<int>;

//std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};

int main() {
	
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int n;
	std::cin >> n;
	int prel = -1, prer = -1;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int a;
		char s;
		std::cin >> a >> s;
		if(s == 'L') {
			if(prel == -1) {
				prel = a;
			} else {
				ans += abs(a - prel);
				prel = a;
			}
		} else {
			if(prer == -1) {
				prer = a;
			} else {
				ans += abs(a - prer);
				prer = a;
			}
		}
	}
	std::cout << ans;

	return 0;
}